Skip to content

Extract _WatchedFieldBase to share logic between sync and async watchers#95

Merged
zeevdr merged 1 commit into
mainfrom
refactor/watched-field-base
May 25, 2026
Merged

Extract _WatchedFieldBase to share logic between sync and async watchers#95
zeevdr merged 1 commit into
mainfrom
refactor/watched-field-base

Conversation

@zeevdr
Copy link
Copy Markdown
Member

@zeevdr zeevdr commented May 24, 2026

Summary

  • WatchedField and AsyncWatchedField shared ~90% of their code with no base class, causing silent drift (the sync version read _value outside its own lock when firing callbacks; the async version had no equivalent guard at all).
  • Extracts _WatchedFieldBase with _apply_raw and _fire_callbacks helpers so the mutation and notification logic lives in exactly one place.
  • Consolidates the three _RECONNECT_* constants that were copy-pasted into both modules.

Test plan

  • make test — all 227 tests pass, coverage 97.3% (above 95% threshold)
  • _watcher_base.py reaches 100% coverage via the existing watcher test suites
  • make lint — ruff clean, no format drift

Closes #60

…async field logic

The two WatchedField classes shared ~90% of their implementation but had
no common base, causing drift (the sync version acquired a lock in _update
but then read _value outside it for the callback; the async version had no
lock at all). Extract _WatchedFieldBase with _apply_raw and _fire_callbacks
helpers. Both subclasses call super().__init__, inherit path/on_change/__bool__,
and delegate value-mutation to the base—with or without a lock as appropriate.
The three _RECONNECT_* constants are also consolidated in the new module.

Closes #60

Co-Authored-By: Claude <noreply@anthropic.com>
@zeevdr zeevdr added this to the Beta Readiness milestone May 24, 2026
@zeevdr zeevdr added size: M Moderate — a day or two, clear scope priority: P2 Nice-to-have labels May 24, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zeevdr zeevdr merged commit b2cdf36 into main May 25, 2026
15 checks passed
@zeevdr zeevdr deleted the refactor/watched-field-base branch May 25, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P2 Nice-to-have size: M Moderate — a day or two, clear scope

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: extract _WatchedFieldBase to share logic between sync and async watchers

1 participant